/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VerDisciplinaPorPeriodo.java
 *
 * Created on 28/11/2012, 16:02:12
 */
package distribuicaoDeProfessores;

/**
 *
 * @author Jaime
 */
public class VerDisciplinaPorPeriodo extends javax.swing.JPanel {
    Disciplinas disciplinas;
    JanelaPrincipal janela;
    /** Creates new form VerDisciplinaPorPeriodo */
    public VerDisciplinaPorPeriodo(Disciplinas disciplinas, JanelaPrincipal janela) {
        this.disciplinas = disciplinas;
        this.janela = janela;
       
        initComponents();
        atualizar(disciplinas);
    }

   /* public void remover(){
        for(int i = 0; i < modeloDisciplina.getRowCount(); i++)
            modeloDisciplina.removeRow(0);
    }*/
    public void atualizar(Disciplinas disciplinas){
        javax.swing.table.DefaultTableModel modeloDisciplina;
        String nomes[] = new String[3];
        java.text.DecimalFormat format = new java.text.DecimalFormat("000000");
       // for(int i = 0; i < disciplinas.getDisciplinas().size(); i++)
         //   remover();
         modeloDisciplina = new javax.swing.table.DefaultTableModel();
        modeloDisciplina.addColumn("Indice");
        modeloDisciplina.addColumn("Nome");
        modeloDisciplina.addColumn("Periodo");
        for(int i = 0; i < disciplinas.getDisciplinas().size(); i++){
            if(disciplinas.getDisciplinas().get(i).getPeriodo()==periodo.getSelectedIndex()+1)//Teste e só exibide se o perido da disciplina for igual ao do periodo selecinado
            { 
                nomes[0]= format.format(i);
                nomes[1]= disciplinas.getDisciplinas().get(i).getNome();
                nomes[2]= ""+disciplinas.getDisciplinas().get(i).getPeriodo();
                modeloDisciplina.addRow(nomes);
            }
        }
        tabela.setModel(modeloDisciplina);
    this.repaint();
    }   
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        periodo = new javax.swing.JComboBox();
        jScrollPane2 = new javax.swing.JScrollPane();
        tabela = new javax.swing.JTable();

        setLayout(new java.awt.BorderLayout());

        jPanel1.setBackground(new java.awt.Color(255, 255, 204));
        jPanel1.setLayout(new java.awt.BorderLayout());

        jLabel1.setBackground(new java.awt.Color(255, 255, 204));
        jLabel1.setFont(new java.awt.Font("Script MT Bold", 1, 36)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 204, 0));
        jLabel1.setText("Ver Disciplina / Periodo");
        jPanel1.add(jLabel1, java.awt.BorderLayout.PAGE_START);

        jPanel2.setBackground(new java.awt.Color(255, 255, 153));
        jPanel2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        jPanel2.setLayout(new java.awt.BorderLayout());

        periodo.setBackground(new java.awt.Color(255, 255, 204));
        periodo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1º Periodo", "2º Periodo", "3º Periodo", "4º Periodo", "5º Periodo", "6º Periodo", "7º Periodo", "8º Periodo" }));
        periodo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                periodoActionPerformed(evt);
            }
        });
        jPanel2.add(periodo, java.awt.BorderLayout.PAGE_START);

        tabela.setBackground(new java.awt.Color(255, 255, 153));
        tabela.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tabela.setGridColor(new java.awt.Color(0, 204, 0));
        jScrollPane2.setViewportView(tabela);

        jPanel2.add(jScrollPane2, java.awt.BorderLayout.CENTER);

        jPanel1.add(jPanel2, java.awt.BorderLayout.CENTER);

        jScrollPane1.setViewportView(jPanel1);

        add(jScrollPane1, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

    private void periodoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_periodoActionPerformed
       janela.acaoVerDisciplinaPorPeriodo();
    }//GEN-LAST:event_periodoActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JComboBox periodo;
    private javax.swing.JTable tabela;
    // End of variables declaration//GEN-END:variables

}
